package com.wang.gulimall.coupon.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.common.utils.PageUtils;
import com.wang.common.utils.Query;

import com.wang.gulimall.coupon.dao.SeckillPromotionDao;
import com.wang.gulimall.coupon.entity.SeckillPromotionEntity;
import com.wang.gulimall.coupon.service.SeckillPromotionService;


@Service("seckillPromotionService")
public class SeckillPromotionServiceImpl extends ServiceImpl<SeckillPromotionDao, SeckillPromotionEntity> implements SeckillPromotionService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<SeckillPromotionEntity> queryWrapper = new QueryWrapper<SeckillPromotionEntity>();
        //1、获取key
        String key = (String) params.get("key");
        String promotionSessionId = (String) params.get("promotionSessionId");
        if (!StringUtils.isEmpty(key)) {
            queryWrapper.eq("id", key);
        }
        if (!StringUtils.isEmpty(promotionSessionId)) {
            queryWrapper.eq("promotion_session_id", promotionSessionId);
        }
        IPage<SeckillPromotionEntity> page = this.page(
                new Query<SeckillPromotionEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }
}